package com.example.design.nioandnettty.practice.websocketLongCon;

import com.alibaba.nacos.common.utils.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Description TODO
 * @date 2023/9/27 13:14
 * @Author liuzhihui
 * @Version 1.0
 */
@RestController
public class WebSocketComplexTestController {
    /**
     * 服务端给指定客户端推送数据
     */
    @GetMapping("/sendMsgToClient")
    public void sendMsgToClient(Long userId, String message) {
        if (userId ==null) {
            userId = 1L;
        }
        if (StringUtils.isEmpty(message)) {
            message = "aaa";
        }
        WebSocketHandler.sendMsgToClient(userId, message);
    }

    /**
     * 服务端推送数据给所有客户端
     */
    @GetMapping("/sendMsgToAllClient")
    public void sendMsgToAllClient(String message) {
        if (StringUtils.isEmpty(message)) {
            message = "aaa";
        }
        WebSocketHandler.sendMsgToAllClient(message);
    }

    /**
     * 获取在线客户数
     */
    @GetMapping("/getOnlineClientNum")
    public Integer getOnlineClientNum() {
        return WebSocketHandler.getOnlineClientNum();
    }

    @GetMapping("/hi")
    public String hi() {
        return "hi";
    }
}
